<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "bus_employee".
 *
 * @property integer $employee_id
 * @property string $employee_name
 * @property string $employee_mobile
 * @property integer $del_flag
 * @property string $shop_id
 * @property string $login_name
 * @property string $create_time
 * @property string $boss_uid
 */
class BusEmployee extends \yii\db\ActiveRecord
{
	private $errorMessage;
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'bus_employee';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['employee_name', 'employee_mobile', 'shop_id', 'login_name'], 'required'],
            [['del_flag', 'shop_id', 'boss_uid'], 'integer'],
            [['create_time'], 'safe'],
            [['employee_name'], 'string', 'max' => 12],
            [['employee_mobile', 'login_name'], 'string', 'max' => 45]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'employee_id' => 'Employee ID',
            'employee_name' => 'Employee Name',
            'employee_mobile' => 'Employee Mobile',
            'del_flag' => 'Del Flag',
            'shop_id' => 'Shop ID',
            'login_name' => 'Login Name',
            'create_time' => 'Create Time',
            'boss_uid' => 'Boss Uid',
        ];
    }
    /*模块交互接口  */
    /**
     * 增加员工提成记录
     * @date: 2016-2-22 
     * @author: futao
     * @param integer $shopId
     * @param integer $bossId
     * @param array $data 
     * @param $data['sell_reward']        销售业绩
     * @param $data['consume_reward']     消耗业绩
     * @param $data['handwork_reward']    手工提成
     * @param $data['epiboly_reward']     合作项目提成
     * @param $data['employee_id']        员工ID
     */
    public function addEmployeereward($shopId,$bossId,$data)
    {
    	if(intval($shopId)<1 || intval($bossId)<1){
    		$this->setError('店长老板ID错误！');
    		return false;
    	}
    	if(!is_array($data)){
    		$this->setError('data必须是数组!');
    		return false;
    	}
    	if((intval($data['employee_id'])<0) || ($data['sell_reward']=='' && $data['consume_reward']=='' && $data['handwork_reward']=='' && $data['epiboly_reward']=='')){
    		$this->setError('参数不全！');
    		return false;
    	}
    	$rewardModel = new BusEmployeeReward();
    	$rewardModel->employee_id = $data['employee_id'];
    	$rewardModel->shop_id = $shopId;
    	$rewardModel->boss_id = $bossId;
    	$rewardModel->sell_reward = $data['sell_reward'] ? $data['sell_reward'] : '';
    	$rewardModel->consume_reward = $data['consume_reward'] ? $data['consume_reward'] : '';
    	$rewardModel->handwork_reward = $data['handwork_reward'] ? $data['handwork_reward'] : '';
    	$rewardModel->epiboly_reward = $data['epiboly_reward'] ? $data['epiboly_reward'] : '';
    	$rewardModel->create_time = date("Y-m-d H:i:s",time());
    	if($rewardModel->save(false)){
    		return true;
    	}else{
    		$this->setError('添加失败！');
    		return false;
    	}
    }
    /**
     * 获取错误信息
     * @date: 2016-2-24 
     * @author: futao
     */
    public function getError(){
    	return $this->errorMessage;
    }
    /**
     * 设置错误信息
     * @date: 2016-2-24 
     * @author: futao
     */
    public function setError($message){
    	$this->errorMessage = $message;
    }
    /*end  */
}
